﻿<%@ Page Title="" Language="C#" MasterPageFile="~/_Default.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication.Default1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <%=""%>
    <div class="index-container">
        <%--需求--%>
        <div class="layui-tab layui-tab-brief index-tab" style="margin-top: 0px;">
            <ul class="layui-tab-title">
                <li class="layui-this">插画约稿【让画师交押金的都是骗子！遇到直接举报！】</li>
            </ul>
            <a class="tab-item" href="/Projects.aspx">查看更多
            </a>
        </div>

        <div class="layui-row layui-col-space10">

            <% if (projects.Count > 0)
                { %>
            <% foreach (Models.Projects project in projects)
                { %>

            <div class="layui-col-md6">
                <div class="project-item" url="/Project/Detail.aspx?id=<%=project.ProjectID %>">
                    <div class="info flex-grow-1">
                        <div class="flex-container">
                            <div class="flex-grow-1 title text-ellipsis">
                                <%=project.Title %>
                            </div>
                            <div class="flex-shrink-0  price">
                                ¥ <%=project.PriceMin %> ~ <%=project.PriceMax %>
                            </div>
                        </div>
                        <div class="created">
                            <span class="nickname text-ellipsis"><%=project.Owner.NickName %></span>
                            发布于<%=project.CreatedAt %>
                        </div>
                        <div class="tag">
                            <% if (project.Identity == 1)
                                {%>
                            <span class="el-tag el-tag--mini el-tag--light">私人</span>
                            <%} %>
                            <% if (project.Identity == 2)
                                {%>
                            <span class="el-tag el-tag--mini el-tag--light">社团/店铺</span>
                            <%} %>
                            <% if (project.Identity == 3)
                                {%>
                            <span class="el-tag el-tag--mini el-tag--light">公司企业</span>
                            <%} %>

                            <%
                                List<string> tags = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(project.Tag);
                                tags.Remove("@");
                                foreach (string tag in tags)
                                {
                            %>
                            <span class="el-tag el-tag--info el-tag--mini el-tag--light"><%=tag %></span>
                            <%} %>
                        </div>
                        <div class="info2">
                            <div class="label-wrapper">
                                <span class="label">截稿日期：</span>
                                <span class="value"><%=project.Deadline.ToString("yyyy-MM-dd") %></span>
                            </div>
                            <div class="label-wrapper">
                                <span class="label">应征人数：</span>
                                <span class="value"><%=project.ApplyCount %></span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <%} %>

            <script>
                $('.project-item').on('click', e => {
                    let url = $(e.delegateTarget).attr("url");
                    if (url) {
                        window.open(url);
                    }
                })
            </script>
            <%}
                else
                { %>

            <div class="empty"></div>

            <%} %>

        </div>



        <%--作品--%>
        <div class="layui-tab layui-tab-brief index-tab">
            <ul class="layui-tab-title" id="art-tab">
                <%-- <li class="layui-this">热门</li>
                <li>最新</li>--%>
            </ul>
            <a class="tab-item" href="Arts.aspx">查看更多
            </a>
        </div>

        <script>
            $(function () {
                const urlParasm = 'art';
                const tabId = '#art-tab';
                let tabList = [
                    { name: '热门', value: 'LikeCount' },
                    { name: '最新', value: 'CreatedAt' }
                ]
                tabList = tabList.map(item => {
                    const currentParams = new URL(location.href).searchParams.get(urlParasm) || tabList[0].value;
                    return `<li value="${item.value}" class="${currentParams === item.value ? "layui-this" : ""}">${item.name}</li>`
                }).join("");
                $(tabId).append(tabList);
                $(tabId).find('li').on('click', e => {
                    let url = new URL(location.href);
                    url.searchParams.set(urlParasm, $(e.target).attr('value'));
                    location.href = url;
                })
            })
        </script>

        <div class="layui-row layui-col-space10">
            <% if (artworks.Count != 0)
                { %>
            <% foreach (Models.Artworks item in artworks)
                {%>
            <div class="layui-col-md2">
                <div class="art-item">
                    <div class="cover-wrapper"
                        url="Art/Detail.aspx?id=<%=item.ArtworkID %>"
                        style="background-image: url(<%=item.Cover.Substring(1, item.Cover.Length - 1) %>);">
                        <div class="type">
                            <a href="User/Resume.aspx?id=<%=item.OwnerID %>" target="_blank"><span class="color-money">¥ 找TA约稿 ¥</span></a>
                        </div>
                    </div>
                    <div class="flex-container user-wrapper">
                        <a style="font-size: 0px;" href="User/Arts.aspx?id=<%=item.OwnerID %>" target="_blank">
                            <span class="avatar" style="width: 24px; height: 24px;">
                                <img src="<%=item.Owner.AvatarUrl.Substring(1, item.Owner.AvatarUrl.Length - 1) %>" />
                            </span>
                        </a>
                        <a class="nickname flex-grow-1" href="User/Arts.aspx?id=<%=item.OwnerID %>" target="_blank"><%=item.Owner.NickName %></a>
                        <div class="like flex-shrink-0 <%=item.IsLike?"liked":"" %>" id="<%=item.ArtworkID %>">
                            <i class="iconfont icon-zan"></i>
                            <span class="count"><%=item.LikeCount %></span>
                        </div>
                    </div>
                </div>
            </div>
            <%} %>
            <script>
                $('.art-item .cover-wrapper').on('click', e => {
                    if ($(e.target).attr("url")) {
                        window.open($(e.target).attr("url"));
                    }
                })
                $('.like').on('click', e => {
                    let node = e.delegateTarget;
                    $.ajax({
                        url: 'Art/Handle.aspx',
                        method: "post",
                        data: {
                            action: "Like",
                            id: $(node).attr("id")
                        },
                        success: (msg) => {
                            location.reload();
                        }
                    })
                })
            </script>
            <%}
                else
                {%>
            <div class="empty"></div>
            <%} %>
        </div>

        <%--用户--%>
        <div class="layui-tab layui-tab-brief index-tab">
            <ul class="layui-tab-title">
                <li class="layui-this" style="display: none;">最近获赞</li>
                <li class="layui-this">最新入驻</li>

            </ul>
            <a class="tab-item" href="/Artists.aspx">查看更多
            </a>
        </div>

        <div class="layui-row">

            <% if (users.Count > 0)
                { %>
            <% foreach (Models.User user in users)
                { %>

            <div class="layui-col-md12">
                <div class="artist-item">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-md2">
                            <div class="artist-header">
                                <a href="User/Arts.aspx?id=<%=user.UserID %>" target="_blank">
                                    <div class="avatar-wrapper">
                                        <span class="avatar"
                                            style="width: 60px; height: 60px; cursor: pointer;">
                                            <img
                                                src="<%=user.UserInfo.AvatarUrl.Substring(1) %>" /></span><span
                                                    class="alias"></span>
                                    </div>
                                </a>
                                <div class="nickname">
                                    <%=user.UserInfo.NickName %>
                                    <i class="iconfont <%=user.UserInfo.Sex == 1 ? "icon-nv" : user.UserInfo.Sex == 2 ? "icon-nan" : "" %>" style="font-size: 16px;"></i>
                                </div>
                                <div class="lm">
                                    <div class="lmid"><span class="prefix">联盟ID</span><span class="id"><%=user.UserID %></span></div>
                                </div>
                                <a class="layui-btn layui-btn-danger-2" href="Resume.aspx?id=<%=user.UserID %>" target="_blank">约稿
                                </a>
                            </div>
                        </div>
                        <div class="layui-col-md4">
                            <div class="tags">
                                <% 
                                    if (!string.IsNullOrEmpty(user.ResumeInfo.IdentityTag))
                                    {
                                %>
                                <span class="el-tag el-tag--mini el-tag--light"><%=user.ResumeInfo.IdentityTag %></span>
                                <%} %>

                                <% 
                                    string tag = user.ResumeInfo.Tag;
                                    List<string> tags = new List<string>();
                                    if (tag != null)
                                    {
                                        tags = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(tag);
                                    }
                                    if (tags.Count > 0)
                                    {
                                        tags.Remove("@");
                                    }

                                    foreach (string t in tags)
                                    {
                                %>
                                <span class="el-tag el-tag--info el-tag--mini el-tag--light"><%=t %></span>
                                <%} %>
                            </div>
                            <div class="intro">
                                <div class="resume-info">
                                    <span class="label">简介：</span>
                                    <div class="content"><%=(user.ResumeInfo.Intro == null || user.ResumeInfo.Intro == "") ? "未填写" : user.ResumeInfo.Intro %></div>
                                </div>
                                <div class="resume-info">
                                    <span class="label">经验：</span>
                                    <div class="content"><%=(user.ResumeInfo.Experience == null || user.ResumeInfo.Experience == "") ? "未填写" : user.ResumeInfo.Experience %></div>
                                </div>
                                <div class="resume-info">
                                    <span class="label">联系：</span>
                                    <div class="content"><%=(user.ResumeInfo.Contact == null || user.ResumeInfo.Contact == "") ? "未填写" : user.ResumeInfo.Contact %></div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <div class="layui-row layui-col-space10">

                                <% if (user.Artworks.Count > 0)
                                    { %>
                                <% foreach (Models.Artworks artwork in user.Artworks.Take(4))
                                    { %>
                                <div class="layui-col-sm3" style="float: right;">
                                    <div class="art-item">
                                        <a style="display: block;" href="../Art/Detail.aspx?id=<%=artwork.ArtworkID %>" target="_blank">
                                            <div class="cover-wrapper"
                                                style="background-image: url(<%=artwork.Cover.Substring(1)%>); height: 200px;">
                                            </div>
                                        </a>
                                    </div>
                                </div>
                                <%} %>
                                <%}
                                    else
                                    { %>
                                <div style="height: 207px; display: flex; align-items: center; justify-content: center;">
                                    暂无作品
                                </div>
                                <%} %>
                            </div>
                        </div>

                    </div>
                </div>
            </div>

            <%} %>
            <%}
                else
                { %>
            <div class="empty"></div>
            <%} %>
        </div>


    </div>
</asp:Content>
